//Nathan Popham
//4003-573-01: Procedural Shading
//Lab 2
//
//Phong shader
//This is a crappy phong shader that can't do the back
//of objects.

surface
realPhong ( float Ka = 0.2, 
            Kd = 0.5, 
            Ks = 0.5,
            roughness = 0.1; 
	        color specularcolor = (1, 1, 1);
          )
{


    
    float diff = 0;
    float spec = 0;
    normal Nn = normalize(N); 
    
    extern point P;
    illuminance (P, Nn, PI) {
       extern vector L;
       normal Ln = normalize(L);
       float NdotL = max(Nn . Ln, 0.0);
       
       if(NdotL > 0.0)
       {
           diff += Kd*NdotL;
           normal R = normalize(reflect(-Ln, Nn));
           float RdotV = max(R . -normalize(I), 0.0); 
           spec += Ks*(RdotV)*roughness;
       }
    }
    Ci = Cs * (Ka*ambient() + diff) + 
	 specularcolor * spec;
    Oi = Os;  
    Ci *= Oi;
}
